<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户详情</title>

    <link href="../../resource/css/bootstrap.min.css?v=3.3.5" rel="stylesheet"
          th:href="@{/resource/css/bootstrap.min.css?v=3.3.5}"/>
    <link href="../../resource/hotui/css/font-awesome.min.css" th:href="@{/resource/hotui/css/font-awesome.min.css}"
          rel="stylesheet">
    <!-- Morris -->
    <link href="http://cdn.viptool.cn/lib/morris.js/0.4.3/morris.css" rel="stylesheet">
    <link href="../../resource/hotui/css/style.min-1.0.8.css" th:href="@{/resource/hotui/css/style.min-1.0.8.css}"
          rel="stylesheet">
    <link href="../../resource/hotui/css/hotui.style.override.css"
          th:href="@{/resource/hotui/css/hotui.style.override.css}" rel="stylesheet"/>
    <link href="../../resource/lib/imageview/css/imageviewer.css" rel="stylesheet"/>
    <link href="../../resource/lib/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css" type="text/css"
          th:href="@{/resource/lib/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css}" rel="stylesheet"/>
    <script src="../../resource/js/jquery.min.js?v=2.1.4" th:src="@{/resource/js/jquery.min.js?v=2.1.4}"></script>
    <script src="../../resource/js/bootstrap.min.js?v=3.3.5" th:src="@{/resource/js/bootstrap.min.js?v=3.3.5}"></script>
    <script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316"
            th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316(123123)}"></script>
    <script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316"
            th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-init.js}"></script>
    <style>
        .user-close-config {
            height: 40px;
            line-height: 40px;
        }

        .user-close-config .control-label {
            margin-left: 20px;
            font-weight: normal !important;
        }

        .user-close-config label.off {
            background-color: red;
            color: #fff;
            margin-right: 10px;
        }

        .user-close-config label.on {
            background-color: #fff;
            color: #674646;
            border: 1px solid #ccc;
            margin-right: 10px;
        }

        .separator {
            margin: 31px 20px 10px 20px;
            border-bottom: 1px solid #ccc;
        }
    </style>
</head>

<body>

<div class="wrapper wrapper-content tooltip-demo">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins m-b-none">
                <div th:replace="fragments/live_fragment::roomDetailFg" class="ibox-title"
                     style="vertical-align: bottom;height: 100%;padding-left: 0;">
                    <h5 style="font-size: 18px;">
                        <img src="../../resource/img/p2.jpg" onerror="this.src='../../resource/img/d_head.jpeg'"
                             alt="" style="width:100px;height:100px;"/>
                    </h5>
                    <div style="margin-left: 120px;width: 50%;margin-top: -6px;">
                        <h3>剑南的直播间</h3>
                        <p style="width: 373px;height: 51px;">
                            非常优秀的直播间非常优秀的直播间非常优秀的直播间非常优秀的直播间非常优秀的直播间非常优秀的直播间非常优秀的直播间</p>
                        <p>创建时间：2012-12-12 12:12:12</p>
                    </div>
                    <button type="button"
                            style="float: right;margin-top: -45px;margin-right: 10px;"
                            class="btn btn-primary btn-xl m-b-none">房间设置
                    </button>
                </div>
                <div class="tabs-container" style="margin-top: 20px;">
                    <ul class="nav nav-tabs">
                        <li class="active">
                            <a th:href="@{/live/detail/products(roomId=${room.id})}" href="user_detail.html">商品管理</a>
                        </li>
                        <li>
                            <a th:href="@{/live/detail/directors(roomId=${room.id})}"
                               href="../user/user_detail_advance_log.html">主播管理</a>
                        </li>
                        <li>
                            <a th:href="@{/live/detail/sessions(roomId=${room.id})}"
                               href="../user/user_detail_advance_log.html">直播记录</a>
                        </li>
                        <li>
                            <a th:href="@{/live/detail/videos(roomId=${room.id})}"
                               href="../user/user_detail_advance_log.html">直接间视频</a>
                        </li>
                        <li sec:authorize="hasRole('ADMIN')">
                            <a th:href="@{/live/detail/images(roomId=${room.id})}"
                               href="../live/live_detail_images.html">直接间图片</a>
                        </li>
                        <li sec:authorize="hasRole('ADMIN')">
                            <a th:href="@{/live/detail/users(roomId=${room.id})}"
                               href="../user/user_detail_advance_log.html">直接间用户列表</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="panel-body">
                                <div>
                                    <form id="saveForm">
                                        <input type="hidden" th:value="${pageIndex}" name="pageIndex"/>
                                    </form>
                                    <div class="form-inline"
                                         style="padding-top: 10px;padding-bottom: 15px;text-align: right;">
                                        <button sec:authorize="hasRole('MERCHANT')"
                                                type="button"
                                                onclick="liveHandler.editProduct(0)"
                                                th:attr="data-roomid=${room.id}"
                                                class="btn btn-primary btn-sm m-b-none">添加商品
                                        </button>
                                    </div>
                                    <div class="table-responsive">

                                        <table class="table table-bordered table-hover table-center">
                                            <thead>
                                            <tr>
                                                <th>商品</th>
                                                <th>价格</th>
                                                <th>尺寸</th>
                                                <th>库存</th>
                                                <th>销售类型</th>
                                                <th>上下架</th>
                                                <th>销售对象</th>
                                                <th>创建时间</th>
                                                <th>操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <tr th:each="product:${products}">
                                                <td style="text-align: left">
                                                    <img style="width: 50px;height: 50px;border-radius: 10px;"
                                                         th:src="${product.mainPic+'?x-oss-process=image/resize,l_200'}"
                                                         src="../../resource/img/p1.jpg">
                                                    <span th:text="${product.productName}">这是一个商品</span>
                                                </td>
                                                <td>￥<span th:text="${product.price}">100.00</span></td>
                                                <td th:text="${product.propSize}">78*76*762</td>
                                                <td th:text="${product.availableStore()}">15</td>
                                                <td>
                                                    <span th:text="${product.saleType.desc}">拍卖</span>
                                                    <th:block th:if="${product.saleType.code==1}">
                                                        <br>
                                                        <span th:class="${product.auctionStatus.statusClass()}"
                                                              th:if="${product.auctionStatus!=null}"
                                                              th:text="${product.auctionStatus.desc}">拍卖中</span>
                                                    </th:block>
                                                </td>
                                                <td th:switch="${product.statusCode}">
                                                    <span th:case="0" class="danger">下架</span>
                                                    <span th:case="1" class="color-success">上架</span>
                                                </td>
                                                <td th:text="${product.exclusiveUserId==null||product.exclusiveUserId==0 ? '公开' : product.exclusiveUserInfo}">
                                                    公开
                                                </td>
                                                <td th:text="${#temporals.format(product.createTime,'yyyy-MM-dd HH:mm:ss')}">
                                                    2019-12-12 12:12:12
                                                </td>
                                                <td>
                                                    <th:block th:if="${product.saleType.code==1}">
                                                        <a href="javascript:liveHandler.auctionModalShow(1,0)"
                                                           th:href="|javascript:liveHandler.auctionModalShow(${product.productId},${product.auctionStatus.code})|">拍卖设置</a>
                                                        |
                                                        <a href="javascript:liveHandler.bidList(1)"
                                                           th:href="|javascript:liveHandler.bidList(${product.productId})|">出价记录</a>
                                                        |
                                                    </th:block>
                                                    <th:block th:if="${product.auctionStatus.code!=2}">
                                                        <a href="javascript:liveHandler.editProduct(1)"
                                                           th:href="|javascript:liveHandler.editProduct(${product.productId})|">编辑</a>
                                                        |
                                                    </th:block>
                                                    <th:block
                                                            th:if="${product.saleType.code==0||product.auctionStatus.code==2}">

                                                        <a href="javascript:void(0);" onclick="liveHandler.up(this)"
                                                           th:attr="data-productid=${product.productId}"
                                                           th:if="${product.statusCode==0}">上架</a>

                                                        <a href="javascript:void(0);" onclick="liveHandler.down(this)"
                                                           th:attr="data-productid=${product.productId}"
                                                           th:if="${product.statusCode==1}">下架</a>
                                                        |
                                                    </th:block>

                                                    <th:block
                                                            th:if="${product.saleType.code==0||product.auctionStatus.code==2}">
                                                        <a href="javascript:void(0);"
                                                           onclick="liveHandler.del(this)"
                                                           th:attr="data-productid=${product.productId}">删除</a>
                                                    </th:block>
                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                    <p style="float: left; margin: 20px 0;">
                                        共<span th:text="${totalRecords}"></span>条记录，当前第<span
                                            th:text="${pageIndex}"></span>/<span
                                            th:text="${totalPages==0?1:totalPages}"></span>，每页20条记录
                                    </p>
                                    <ul style="float: right;" class="pagination pagination-split">
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script type="text/html" id="add_director_template">
    <div class="form-horizontal" style="width: 600px;">
        <div class="form-group">
            <label class="col-sm-2 control-label">选择用户:</label>

            <div class="col-sm-10 form-inline">
                <input style="width: 200px" id="add_search_user" type="text" class="form-control input-sm"
                       placeholder="用户手机/昵称"/>
                <button onclick="liveHandler.searchUser()"
                        type="button"
                        class="btn btn-primary btn-xs m-b-none pickUpShow"
                        style="margin-left: 20px;">搜索
                </button>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">待选用户:</label>

            <div class="col-sm-10" id="pre_search_content">
            </div>
        </div>
        <div class="hr-line-dashed "></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">已选用户:</label>

            <div class="col-sm-10 form-inline">
                <input type="hidden" id="add_user_id"/>
                <p class="form-control-static"><span id="add_user_name"></span>/<span id="add_user_mobile"></span></p>
            </div>
        </div>
        <div class="hr-line-dashed "></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">粉丝名称:</label>

            <div class="col-sm-10 form-inline">
                <input style="width: 200px" type="text" class="form-control input-sm" id="add_director_name"
                       placeholder="粉丝名称"/>
            </div>
        </div>
    </div>
</script>

<script type="text/html" id="auction_modal">
    <input type="hidden" id="auction_id"/>
    <input type="hidden" id="action_productId"/>
    <div class="form-horizontal" style="width: 600px;">
        <div class="form-group">
            <label class="col-sm-2 control-label">开始时间:</label>

            <div class="col-sm-10">
                <div style="width: 200px" class='input-group date'>
                    <input type="text" readonly class="form-control input-sm m-b-none" id="auction_startTime"
                           placeholder="开始时间"/>
                    <span class="input-group-addon">
                        <span class="glyphicon glyphicon-calendar"></span>
                    </span>
                </div>
            </div>
        </div>
        <div class="hr-line-dashed "></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">拍卖时长:</label>

            <div class="col-sm-10 form-inline">
                <div class="input-group">
                    <div class="input-group m-b">
                        <input type="text" id="auction_duration" class="form-control input-s-sm only-num"
                               placeholder="拍卖时常"> <span class="input-group-addon">分</span>
                    </div>
                </div>
                <p class="form-control-static">结束时间：<span id="auction_endTime"></span></p>
            </div>
        </div>
        <div class="hr-line-dashed "></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">起拍价:</label>
            <div class="col-sm-4">
                <div class="input-group">
                    <span class="input-group-addon">¥</span>
                    <input name="price" id="auction_startingPrice" value="1" type="text"
                           class="form-control input-s-sm only-float" placeholder="起拍价">
                </div>
            </div>
        </div>
        <div class="hr-line-dashed "></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">加价幅度:</label>
            <div class="col-sm-4">
                <div class="input-group">
                    <span class="input-group-addon">¥</span>
                    <input name="price" id="auction_unitIncrease" value="1" type="text"
                           class="form-control input-s-sm only-float" placeholder="加价幅度">
                </div>
            </div>
        </div>
        <div class="hr-line-dashed "></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">是否延时:</label>
            <div class="col-sm-10">
                <select style="width: 100px;" class="form-control input-sm mb10" id="auction_delay"
                        name="auction_delay">
                    <option value="0">否</option>
                    <option value="1">是</option>
                </select>
                <p class="form-control-static color-danger">
                    否：倒计时结束即截拍<br/>
                    是：倒计时结束10秒内如果有新的出价会延长截拍时间，每次延长10秒，系统最多只延长3次
                </p>
            </div>
        </div>
        <div class="hr-line-dashed " style="display: none"></div>
        <div class="form-group" style="display: none">
            <label class="col-sm-2 control-label">保证金:</label>
            <div class="col-sm-4">
                <div class="input-group">
                    <span class="input-group-addon">¥</span>
                    <input name="price" id="auction_securityDeposit" value="0" type="text"
                           class="form-control input-s-sm only-float" placeholder="保证金">
                </div>
            </div>
        </div>
    </div>
</script>

<script type="text/html" id="sel_user_template">
    <div class="form-inline">
        <p class="form-control-static">{{nickname}}/{{mobile}}</p>
        <button onclick="liveHandler.selUser({{userId}},'{{nickname}}','{{mobile}}')"
                type="button"
                class="btn btn-primary btn-xs m-b-none pickUpShow"
                style="margin-left: 20px;">选择
        </button>
    </div>
    <p style="height: 7px;"></p>
</script>
<script src="../../resource/js/jquery.min.js?v=2.1.4" th:src="@{/resource/js/jquery.min.js?v=2.1.4}"></script>
<script src="../../resource/js/bootstrap.min.js?v=3.3.5" th:src="@{/resource/js/bootstrap.min.js?v=3.3.5}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20200720}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-init.js}"></script>
<script src="../../resource/hotui/js/content.min.js" th:src="@{/resource/hotui/js/content.min.js}"></script>
<script src="../../resource/lib/imageview/js/imageviewer.min.js"
        th:src="@{/resource/lib/imageview/js/imageviewer.min.js}"></script>
<script src="../../resource/lib/moment.min.js" th:src="@{/resource/lib/moment.min.js}"></script>
<script src="../../resource/lib/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"
        th:src="@{/resource/lib/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js}"></script>
<script type="text/javascript" th:inline="javascript">
    const pageIndex = /*[[${pageIndex}]]*/  1;
    const totalPages = /*[[${totalPages}]]*/  0;
    const pageUri = /*[[@{/live/detail/products}]]*/  "";
    const editProductUri = /*[[@{/product/liveSimpleEdit}]]*/  "";
    const apiUri = /*[[@{/live/detail/directors}]]*/  "";
    const auctionUri = /*[[@{/auction}]]*/  "";
</script>
<script type="text/javascript">
    var addModal = $("#add_director_template").modal("选择专属用户", function () {
        liveHandler.addUser();
    });

    var auctionModal = $("#auction_modal").modal("拍卖设置", function () {
        let productId = $("#action_productId").val();
        let startTime = $("#auction_startTime").val();
        let duration = $("#auction_duration").val();
        let startingPrice = $("#auction_startingPrice").val();
        let unitIncrease = $("#auction_unitIncrease").val();
        let securityDeposit = $("#auction_securityDeposit").val();
        let roomId = $("#hdRoomId").val();
        let delay = $("#auction_delay").val();


        let requestData = {
            id: $("#auction_id").val(),
            productId: productId,
            startTime: startTime,
            duration: duration,
            startingPrice: startingPrice,
            unitIncrease: unitIncrease,
            securityDeposit: securityDeposit,
            roomId: roomId,
            delay: delay
        };

        hot.ajax(auctionUri + "/edit", requestData, function (apiResult) {
            if (apiResult.resultCode === 2000) {
                hot.tip.success("设置成功", function () {
                    window.location.reload();
                });
            } else {
                hot.tip.error(apiResult.resultMsg);
            }
        }, function () {
        }, "post", 300);
    });
    var modalLayerIndex = '';
    $(function () {
        //初始化分页
        var pageinate = new hot.paging(".pagination", pageIndex, totalPages, 7);

        pageinate.init(function (p) {
            liveHandler.search(p);
        });
    });

    var liveHandler = {
        addModalShow: function () {
            addModal.show();
        },
        searchUser: function () {
            let userKey = $.trim($("#add_search_user").val());
            if (userKey.length === 0) {
                return;
            }
            hot.ajax(apiUri + "/findUser", {
                userKey: userKey
            }, function (apiResult) {
                $("#pre_search_content").empty();
                if (apiResult.data.length === 0) {
                    $("#pre_search_content").html('<p class="form-control-static">未找到相关用户</p>');
                    return;
                }
                $.each(apiResult.data, function (o, item) {
                    let tempHtml = $("#sel_user_template").html();
                    tempHtml = tempHtml.replace("{{userId}}", item.userId);
                    tempHtml = tempHtml.replace(/{{nickname}}/g, item.nickname);
                    tempHtml = tempHtml.replace(/{{mobile}}/g, item.mobile);
                    $("#pre_search_content").append(tempHtml);
                })
            }, function () {
            }, "post");
        },
        bidList: function (productId) {
            let uri = auctionUri + "/bidList?productId=" + productId;
            hot.iframeModal(uri, '400px', '600px', "出价记录");
        },
        auctionModalShow: function (productId, code) {
            let options = {
                btn: ["确定", "关闭"]
            };
            if (code === 2) {
                options.btn = [];
            }
            auctionModal.show(function () {
                $("#auction_startTime").datetimepicker({
                    autoclose: true,
                    format: 'yyyy-mm-dd hh:ii:ss',
                    minuteStep: 1
                });
                $("#auction_endTime").datetimepicker({
                    autoclose: true,
                    format: 'yyyy-mm-dd hh:ii:ss',
                    minuteStep: 1
                });
                $("#action_productId").val(productId);
                hot.ajax(auctionUri + "/currentSession", {
                    productId: productId
                }, function (apiResult) {
                    $("#auction_startTime").val(apiResult.data.startTime);
                    $("#auction_duration").val(apiResult.data.duration);
                    $("#auction_unitIncrease").val(apiResult.data.unitIncrease);
                    $("#auction_startingPrice").val(apiResult.data.startingPrice);
                    $("#auction_securityDeposit").val(apiResult.data.securityDeposit);
                    $("#auction_endTime").html(apiResult.data.endTime);
                    $("#auction_delay").val(apiResult.data.delay ? '1' : '0');
                }, function () {
                }, "get");

            }, options);
        },
        selUser: function (userId, nickname, mobile) {
            $("#add_user_id").val(userId);
            $("#add_user_name").html(nickname);
            $("#add_user_mobile").html(mobile);
            $("#add_director_name").val(nickname);
        },
        addUser: function () {
            $('#productEdit').find('iframe')[0].contentWindow.pageHandler.selectUserComplete({
                userId: $("#add_user_id").val(),
                nickname: $("#add_user_name").html(),
                mobile: $("#add_user_mobile").html()
            });
            addModal.hide();
        },
        search: function (pageIndex) {
            let roomId = $("#hdRoomId").val();
            window.location.href = pageUri + "?roomId=" + roomId + "&pageIndex=" + pageIndex;
        },
        selectUserShow: function (callback) {
            addModal.show();
        },
        add: function (obj) {
            var roomid = $(obj).data('roomid');
            hot.iframeModal("/product/liveSimpleEdit?productId=0&roomId=" + roomid, '800px', '600px', "直播产品添加");
        },
        up: function (obj) {
            var productid = $(obj).data('productid');
            this._changeStatus(productid, 1);
        },
        down: function (obj) {
            var productid = $(obj).data('productid');
            this._changeStatus(productid, 0);
        },
        _changeStatus: function (productId, status) {
            var self = this;
            hot.confirm('确定操作？', function () {
                var tip = status == 1 ? '上架成功' : '下架成功';
                hot.ajax("/product/changeStatus", {
                    productId: productId,
                    status: status
                }, function (data) {
                    if (data.resultCode === 2000) {
                        layer.msg(tip);
                        setTimeout(function () {
                            self.reload();
                        }, 350)
                    } else {
                        layer.msg("失败：" + data.resultMsg);
                    }
                }, function () {
                }, "post", 100);
            });
        },
        del: function (obj) {
            var productid = $(obj).data('productid');
            var self = this;
            hot.confirm('删除后将不可恢复，确定删除？', function () {
                hot.ajax("/product/liveDel", {
                    productId: productid
                }, function (data) {
                    if (data.resultCode === 2000) {
                        layer.msg('删除成功');
                        self.reload();
                    } else {
                        layer.msg("失败：" + data.resultMsg);
                    }
                }, function () {
                }, "post", 100);
            });
        },
        reload: function () {
            window.location.href = window.location.href;
        },
        editProduct: function (productId) {
            let roomId = $("#hdRoomId").val();
            let uri = editProductUri + "?productId=" + productId + "&roomId=" + roomId;
            hot.iframeModal(uri, '800px', '600px', "添加直播产品", {id: 'productEdit'})
        }
    }
</script>
</body>

</html>